<template>
  <div>
    <div style="margin-top: 20px;">
      <el-card>
        <div slot="header" class="clearfix">
          <span>支付类型</span>
        </div>
        <div>
          <el-button type="success" @click="payInsert()">添加支付类型</el-button>
        </div>
        <el-table :data="tableData" style="width: 100%" @selection-change="changeFun">
          <el-table-column type="selection" width="55" />
          <el-table-column label="编号" prop="id" width="130" />
          <el-table-column label="支付类型" prop="pay_type_name" width="130" />
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="payUp(scope.row.id)">修改</el-button>
              <el-button size="mini" type="danger" @click="paydel(scope.row.id)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
  </div>
</template>

<script>
  import {
    PayList,
    PayDel
  } from '../../../api/pay'
  export default {
    data() {
      return {
        tableData: ""
      }
    },
    created() {
      //展示
      PayList().then((response) => {
        if (response.code == 20000) {
          this.tableData = response.data
        }
      })
    },
    methods: {
      //添加
      payInsert() {
        this.$router.push({
          path: '/pay/payInsert',
        })
      },
      //修改
      payUp(id) {
        this.$router.push({
          path: '/pay/payUpate',
          query: {
            id: id
          }
        })
      },
      //删除
      paydel(id) {
        let delid = id
        this.$confirm("是否确认删除本条数据，删除后不可恢复?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "info"
        }).then(() => {
          PayDel(delid).then(res => {
            if (res.code == 20000) {
              this.$message({
                showClose: true, //可关闭的弹窗
                message: '删除成功',
                type: 'success',
                duration: '3000'
              });
              //刷新页面，也可不这样写
              setTimeout(function() {
                window.location.reload();
              }, 1000);
            } else {
              this.$message.error('删除失败');
            }
          })
        })
      },

    }


  }
</script>
